<?php

class DisplayController extends Controller
{
	
	public $layout='//layouts/front';
	
	public function actionIndex()
	{
		/* $criteria = new CDbCriteria;
		$criteria->select='product';  // only select the 'title' column
		$criteria->condition='0=0';
		$product=Post::model()->find($criteria); // $params is not needed */
		$dataProvider=new CActiveDataProvider('Product');
		$this->render('index',array(
				'dataProvider'=>$dataProvider,
		));
	}
	
	public function actionSearch($s){
		$criteria = new CDbCriteria;
		$criteria->select='*';  // only select the 'title' column
		$criteria->condition='name like :name or fullname like :name';
		$criteria->params=array(':name'=>'%'.$s.'%');
		$products=Product::model()->findAll($criteria);
		$dataProvider = new CArrayDataProvider($products, array(
		    'id'=>'product',
		    'sort'=>array(
		        'attributes'=>array(
		             'id', 'name', 'fullname',
		        ),
		    ),
		    'pagination'=>array(
		        'pageSize'=>10,
		    ),
		));
		$this->render('search',array(
				'dataProvider'=>$dataProvider,
		));
	}
	
	public function actionCate($id){
		$criteria = new CDbCriteria;
		$criteria->select='*';  
		$criteria->condition='cateId = :cateId';
		$criteria->params=array(':cateId'=> $id);
		$products=Product::model()->findAll($criteria);
		
		$dataProvider = new CArrayDataProvider($products, array(
				'id'=>'product',
				'sort'=>array(
						'attributes'=>array(
								'id', 'name', 'fullname',
						),
				),
				'pagination'=>array(
						'pageSize'=>10,
				),
		));
		
		$this->render('search',array(
				'dataProvider'=>$dataProvider,
		));
	}
	
	public function actionDetail($id){
		$criteria = new CDbCriteria;
		$criteria->select='*';
		$criteria->condition='id = :id';
		$criteria->params=array(':id'=> $id);
		$product=Product::model()->find($criteria);
		$this->render('detail',array(
				'product'=>$product,
		));
	}
	
	public function actionPosts(){
		$posts=Post::model()->findAll();
		
		$dataProvider = new CArrayDataProvider($posts, array(
				'id'=>'id',
				'sort'=>array(
						'attributes'=>array(
								'createdDate', 'title'
						),
				),
				'pagination'=>array(
						'pageSize'=>10,
				),
		));
		
		$this->render('posts',array(
				'dataProvider'=>$dataProvider,
		));
	}
	
	public function actionPost($id){
		$posts=Post::model()->findAll();
		
		$dataProvider = new CArrayDataProvider($posts, array(
				'id'=>'id',
				'sort'=>array(
						'attributes'=>array(
								'createdDate', 'title'
						),
				),
				'pagination'=>array(
						'pageSize'=>10,
				),
		));
		
		$criteria = new CDbCriteria;
		$criteria->select='*';
		$criteria->condition='id = :id';
		$criteria->params=array(':id'=> $id);
		$post=Post::model()->find($criteria);
		$this->render('post',array(
				'post'=>$post,
				'dataProvider'=>$dataProvider
		));
	}

	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}